/*
 * @Author: szx
 * @Date: 2022-02-13 13:01:53
 * @LastEditTime: 2022-02-13 13:08:47
 * @Description:
 * @FilePath: \leetcode\2000-2099\2000\2000.js
 */

/**
 * @param {string} word
 * @param {character} ch
 * @return {string}
 */
var reversePrefix = function (word, ch) {
    const arr = word.split('');
    const end = word.indexOf(ch);
    for (let i = 0; i <= Math.floor(end / 2); i++) {
        [arr[i], arr[end - i]] = [arr[end - i], arr[i]];
    }
    return arr.join('');
};
console.log(reversePrefix('abcdefd', 'd'));
